package com.yanqu.road.server.cmd.zhaoshang;

import com.yanqu.road.entity.zhaoshang.ZsProject;
import com.yanqu.road.logic.pb.ZhaoShangPb;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.pb.zhaoshang.ZhaoShangProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.zhaoshang.ZsMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = CrossProtocol.C2_ZHAO_SHANG_PROJECT_DETAIL, desc = "项目详情")
public class ZsProjectDetailCmd  extends CrossCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        ZhaoShangProto.ZsProjectDetailReqMsg reqMsg = ZhaoShangProto.ZsProjectDetailReqMsg.parseFrom(packet.getBytes());
        long projectServerId = reqMsg.getServerId();
        ZsProject zsProject;
        if(projectServerId > 0){
            zsProject = ZsMgr.getZsProjectByServerIdAndId(projectServerId, reqMsg.getProjectId());
        }else {
            zsProject = ZsMgr.getZsProjectById(reqMsg.getProjectId());
        }
        ZhaoShangProto.ZsProjectDetailRespMsg.Builder respMsg = ZhaoShangProto.ZsProjectDetailRespMsg.newBuilder();
        if(zsProject != null){
            respMsg.setRet(0);
            ZhaoShangProto.ZsProjectInfoTemp.Builder projectBuilder = ZhaoShangPb.parseZsProjectInfoTemp(zsProject, true, packet.getPlayerId());
            projectBuilder.setStateVal(ZsMgr.calZsProjectStateVal(zsProject));
            projectBuilder.setCross(ZsMgr.inGroup(zsProject.getServerId()));
            respMsg.setProject(projectBuilder);
        }else{
            respMsg.setRet(GameErrorCode.E_ZS_PROJECT_NOT_FOUND);
        }
        MessageHelper.sendPacket(serverId, packet.getPlayerId(), YanQuMessageUtils.buildMessage(Protocol.U_ZS_PROJECT_DETAIL, respMsg));
    }

    @Override
    public void sendData() {

    }
}
